var is_login = false;
$(function(){
	new FlexibleNav(new FlexibleNavMaker('[flexible-nav]').make().prependTo('body') );
	
	$('.auto_img').auto_img();

	$('.box .box_list li').hover(function(){
		$(this).find('.img_info').dequeue().animate({'bottom':0}, 200);
	},function(){
		$(this).find('.img_info').dequeue().animate({'bottom':-34}, 200);
	});
	
	//获取用户信息
	$.get('/u/user_info', function(data){
		var json = null;
		try{
			json = eval('('+data+')');
		}catch(e){
			show_unlogin_info();
			return;
		}
		if(json.authority === true){
			is_login = true;
			$('#site_message').before('<span>您好 '+json.user_name+'，欢迎来到' + SITE_NAME + '！<a href="/u/">用户中心</a> | <a href="/logout.html">注销</a></span>');
		}else{
			show_unlogin_info();
		}
	});
	
	//LazyLoad
	$('img.lazy').lazyload({
		effect : 'fadeIn',
		threshold : 100, 
		load : function(){
			$(this).removeAttr('height').removeAttr('width').auto_img();
		}
	});
	
	var nav_top = $('#main_nav').offset().top;
	
	$(document).scroll(function(){
		var st = $(document).scrollTop();
		if(st>nav_top){
			$('#main_nav').css('top', st);
		}else{
			$('#main_nav').css('top', 100);
		}
	});
});

function show_unlogin_info(){
	$('#site_message').before('<span>您好，欢迎来到' + SITE_NAME + '！请 <a href="/login.html?return_url='+CUR_URL+'">登录</a> | <a href="/regist.html?return_url='+CUR_URL+'">注册</a></span>');
}